<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"  @submit.native.prevent @keyup.enter.native="handleQuery">
      <el-form-item label="反馈人" prop="qKey">
        <el-input v-model="queryParams.qKey" placeholder="姓名" clearable></el-input>
      </el-form-item>
      <el-form-item label="反馈时间" prop="qTimeStartList">
        <el-date-picker
          v-model="queryParams.qTimeStartList"
          type="daterange"
          range-separator="-"
          start-placeholder="起"
          end-placeholder="止"
          value-format="yyyy-MM-dd"
        ></el-date-picker>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['userConfig:feedback:remove']"
        >删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table ref="tables" v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" @sort-change="handleSortChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户名称" align="center" prop="userName" fixed/>
      <el-table-column label="姓名" align="center" prop="nickName" fixed/>
      <el-table-column label="手机号" align="center" prop="phonenumber" />
      <el-table-column label="反馈时间" align="center" prop="createTime" />
      <el-table-column label="反馈意见" align="center" prop="remark" />
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width"  width="150">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            v-hasPermi="['userConfig:feedback:info']"
            @click="handleInfo(scope.row)"
          >详情</el-button>
          &emsp;
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['userConfig:feedback:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 操作日志详细 -->
    <el-dialog title="反馈意见详细" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" label-width="100px" size="mini">
        <el-row>
          <el-input type="hidden" v-model="form.id"/>
          <el-col :span="12">
            <el-form-item label="用户名称：">{{ form.userName }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="姓名：">{{ form.nickName }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="手机号：">{{ form.phonenumber }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="反馈时间：">{{ form.createTime }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="反馈意见：">{{ form.remark }}</el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.notes && form.notes.length > 0">
            <el-form-item label="处理结果：">{{ form.notes }}</el-form-item>
          </el-col>
          <el-col :span="12" v-else>
            <el-form-item label="处理结果" prop="notes">
              <el-input type="textarea" v-model="form.reply"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-input type="hidden" v-if="form.notes && form.notes.length > 0"/>
        <el-button type="primary"  @click="submitForm" v-else>确 定</el-button>
        <el-button @click="open = false">关 闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>


export default {
  name : "Feedback",
  data() {
    return {
      deptList:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 查询参数
      queryParams: {
        qKey: "",
        qIds1: undefined,
        qTimeStartList: undefined,
        qStatus: undefined,
        pageNum: 1,
        pageSize: 10,
        isAsc:undefined,
        orderByColumn:undefined
      },
      dialogTableVisible:false,
    };
  },
  activated() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      this.request({
        url: '/userConfig/feedback/list',
        method: 'get',
        params: this.queryParams
      }).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.isAsc = undefined;
      this.queryParams.orderByColumn = undefined;
      this.queryParams.pageNum = 1;
      this.$refs.tables.clearSort();
      this.getList();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = this.getLowLineCase(column.prop);
      this.queryParams.isAsc = column.order;
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    handleInfo(row) {
      this.open = true;
      this.form = row;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      let deleteIds = row && row.id || this.ids;
      this.$modal.confirm('是否确认删除？').then(() => {
        return this.request({
          url: '/userConfig/feedback/remove/' + deleteIds,
          method: 'delete'
        });
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch((err) => {
        console.log(err)
      });
    },
    /** 提交按钮 */
    submitForm() {

      this.$refs["form"].validate(valid => {
        if (valid) {
          this.request({
            url: '/userConfig/feedback/reply',
            method: 'post',
            data: this.form
          }).then(response => {
            this.$modal.msgSuccess("操作成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
  }
};
</script>

